<?php

namespace iflow\swoole\implement\Server\WebSocket;

use iflow\swoole\ServicesCommand;
use Swoole\WebSocket\Server;

class Service extends \iflow\swoole\implement\Server\Http\Service {

    protected WebSocket $webSocket;

    protected bool $isWebSocket = true;

    public function __construct(protected ServicesCommand $servicesCommand) {
        parent::__construct($this -> servicesCommand);
        $this->webSocket = app(WebSocket::class, [
            $this->servicesCommand -> config -> all(), $this
        ]);

        foreach ($this->webSocket -> getEventsKey() as $eventName => $event) {
            $this->events[$eventName] = $event;
        }
    }

    protected function createServiceAfter(): void {
        parent::createServiceAfter(); // TODO: Change the autogenerated stub
        $this->webSocket -> createRoom();
    }

    protected function getSwooleServiceClass(): string {
        return Server::class;
    }

}